<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <!--表单开始-->

    <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">
      <a-row :gutter="[12,12]">
        <a-col :span="24">
          <a-form-item label="喂养方式" field="kind">
            <smart-dict is-radio v-model="formState.kind" placeholder="请填写喂养方式" :url="DictOptions.GoodsMode"/>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="猪仔品种" field="breed">
            <smart-dict v-model="formState.breed.code" placeholder="请选择猪仔品种" :url="ProductOptions.PigBreedOptions"/>
          </a-form-item>
        </a-col>


        <a-col :span="8">
          <a-form-item label="成长天数" field="day">
            <a-input-number v-model="formState.day" placeholder="请填写成长天数"/>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="达到等级" field="levelNum">
            <a-input v-model="formState.levelNum" placeholder="请填等级序号"/>
          </a-form-item>
        </a-col>


        <a-col :span="8">
          <a-form-item label="预估体重KG" field="weight">
            <a-input-number v-model="formState.weight" placeholder="请填写预估体重KG"/>
          </a-form-item>
        </a-col>


        <a-col :span="12">
          <a-form-item label="达到阶段" field="stage">
            <smart-dict v-model="formState.stage" placeholder="请填写所属阶段" is-radio :url="DictOptions.ProfileStage"/>
          </a-form-item>
        </a-col>


        <a-col :span="12">
          <a-form-item label="是否允许发起宰杀" field="allowKill">
            <a-radio-group v-model="formState.allowKill" is-radio>
              <a-radio :value="false">不允许宰杀</a-radio>
              <a-radio :value="true">允许宰杀</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="喂养提示语" field="msg">
            <a-input v-model="formState.msg" placeholder="请填写喂养提示语"/>
          </a-form-item>
        </a-col>

      </a-row>


    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>


import {EditDrawer} from '@/libs/core'
import {LEVEL_EDIT,} from "../../resource/form";
import {ProductHttp} from '../../resource/http'
import {DictOptions, ProductOptions} from "@/libs/options";


const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])
const {BODY, RULES} = LEVEL_EDIT

const {addLevel, updateLevel} = ProductHttp
const config = {tplRecord: BODY, rawRecord: props.record, rowKey: 'id', emit}
const service = new EditDrawer(config).setAddRequest(addLevel).setUpdateRequest(updateLevel)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改等级' : '新增等级'


</script>
